#include <unistd.h>  
#include <stdlib.h>  
#include <stdio.h>  
#include <string.h>  
#include <errno.h>  
#include <sys/msg.h>
#include <sys/types.h>
#include <sys/ipc.h>

#define BUFSIZ 255

struct msg_buf 
{  
    long  msg_type;  
    char data[BUFSIZ];  
};


int main()
{
	key_t key;
	int msgid;
	int ret;
	struct msg_buf msgbuf;
	
	key = ftok("/tmp/1",'a');
	printf("key= [%x]\n",key);
	msgid = msgget(key,IPC_CREAT|0666);

	if(msgid == -1)
	{
		printf("create error!\n");
		return -1;
	}

	msgbuf.msg_type = (long)123;
	strcpy(msgbuf.data,"hello world");
	ret = msgsnd(msgid,&msgbuf,sizeof(msgbuf.data),IPC_NOWAIT);
	if(ret == -1)
	{
		printf("send to queue error!\n");
		return -1;
	}
}

